/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/

#pragma once

/*-----------------------------------------------------------------------------
	GL driver :
-----------------------------------------------------------------------------*/

struct  EGLVidModeDesc_s {
	uint	width;
	uint	height;
	bool	is_supported;
};

struct  EGLVidState_s	{
	bool	fullscr;
	int		mode;
	HWND	h_wnd;				// Handle to window
	HDC		h_dc;				// Handle to device
	HGLRC   h_gl_rend_context;	// handle to GL rendering context
};

class EGLDriver : public IRSDriver {
	public:
								EGLDriver		( void );
								~EGLDriver		( void );

		virtual void			ResetState		( void );

		virtual bool			CheckFeature	( ERSFeature feature );
		virtual void			GetScreenSize	( uint &w, uint &h );
		virtual void		*	GetWindowHandle	( void );

		virtual IPxTXManager	GetTXM			( void ) { return txm; }
		virtual IPxRTManager	GetRTM			( void ) { return rtm; }
		virtual IPxVBManager	GetVBM			( void ) { return vbm; }
		virtual IPxFXManager	GetFXM			( void ) { return fxm; }

		virtual bool			BeginFrame		( void );
		virtual void			EndFrame		( void );
		
		virtual void			DebugMarker		( const char *text );

	public:
		void	CheckGLExtension	( const char *extname );

	protected:
		bool	features[ RS_FEATURE_MAX ];
		
		void	InitDisplay			( void );
		void	InitGL				( void );
		void	ShutdownDisplay		( void );
		void	ShutdownGL			( void );
		void	CheckDisplayModes	( void );
		
		void	InitGDebugger		( void );
		PFNGLSTRINGMARKERGREMEDYPROC	glStringMarkerGREMEDY;
		
		void	EnumPFDs			( void );
		
		void	InitGLExtensions	( void );

		IPxTXManager		txm;
		IPxRTManager		rtm;
		IPxVBManager		vbm;
		IPxFXManager		fxm;

		static LRESULT	WndProc		( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
		EGLVidState_s	vid_state;

		IPxVar	gl_fullscr;
		IPxVar	gl_stereo;
		IPxVar	gl_mode;
		IPxVar	gl_xpos;
		IPxVar	gl_ypos;
};
